<template>
    <h2>注册页面</h2>
    <table>
        <tr>
            <th>用户名：</th>
            <th>
                <input type="text" placeholder="请输入用户名" v-model="UserName" />
            </th>
        </tr>
        <tr>
            <th>用户密码：</th>
            <th>
                <input type="password" placeholder="请输入用户名" v-model="Password" />
            </th>
        </tr>
        <tr>
            <th>手机号：</th>
            <th>
                <input type="text" placeholder="请输入用户手机号" v-model="Phone" />
            </th>
        </tr>
        <tr>
            <th colspan="2">
                <input type="button" @click="add" value="注册" />
            </th>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter();
const UserName = ref('');
const Password = ref('');
const Phone = ref('');
const add = () => {
    if (UserName.value == '' || Password.value == '') {
        alert("用户名或密码不能为空");
        return;
    }
    if (Phone.value.length != 11) {
        alert("手机号格式不正确");
        return;
    }
    axios.post("http://localhost:53223/api/Tian/AddLogin", {
        UserName: UserName.value,
        Password: Password.value,
        Phone: Phone.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("注册成功");
                router.push("/Loginnnn");
            }
            else {
                alert("注册失败");
                return;
            }
        })
}
</script>